//
//  ModifyPswViewController.m
//  sys_eric
//
//  Created by mac on 11-11-21.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "ModifyPswViewController.h"


@implementation ModifyPswViewController
@synthesize oldpswd;
@synthesize newpswd;
@synthesize makesurepswd;
//这个是建立在UITableViewController的子类上的，还没有完全弄清楚setContentOffset的意义？？？？



- (void)viewDidLoad
{
    self.title=@"修改密码";
    UITableView *tab=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 480) style:UITableViewStyleGrouped];
    self.tableView=tab;
    UIControl *background=[[UIControl alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
    [background addTarget:self action:@selector(backgroundTap) forControlEvents:UIControlEventTouchUpInside];
    self.tableView.backgroundView=background; 
    UIEdgeInsets edgeinsets=UIEdgeInsetsMake(80, 0, 0, 0);//为什么只有前两个参数起作用？？？
    self.tableView.contentInset=edgeinsets;
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    self.tableView.scrollEnabled=NO;
    [tab release];
    [super viewDidLoad];
}

-(void)backgroundTap
{
    [oldpswd resignFirstResponder];
    [newpswd resignFirstResponder];
    [makesurepswd resignFirstResponder];
}


-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
    // Configure the cell...
	switch (indexPath.row) {
		case 0:
        {cell.textLabel.text = @"原密码:";
            UITextField *old=[[UITextField alloc] initWithFrame:CGRectMake(100,4,150, 35)];
		    self.oldpswd=old;
			old.borderStyle = UITextBorderStyleNone;//UITextBorderStyleRoundedRect;
			old.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
			[cell.contentView addSubview:old];
			old.delegate = self;
            old.secureTextEntry=YES;
            old.keyboardType=UIKeyboardTypeNumberPad;
            [old release];
			break;}
		case 1:
        {cell.textLabel.text = @"新密码:";
            UITextField *new=[[UITextField alloc] initWithFrame:CGRectMake(100,4,150, 35)];
		    self.newpswd=new;
			new.borderStyle = UITextBorderStyleNone;//UITextBorderStyleRoundedRect;
			new.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
			[cell.contentView addSubview:new];
			new.delegate = self;
            new.secureTextEntry=YES;
            new.keyboardType=UIKeyboardTypeNumberPad;
            [new release];
			break;}
		case 2:
        {cell.textLabel.text = @"确认密码:";
            UITextField *makesure=[[UITextField alloc] initWithFrame:CGRectMake(100,4,150, 35)];
		    self.makesurepswd=makesure;
			makesure.borderStyle = UITextBorderStyleNone;//UITextBorderStyleRoundedRect;
			makesure.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
			[cell.contentView addSubview:makesure];
			makesure.delegate = self;
            makesure.secureTextEntry=YES;
            makesure.keyboardType=UIKeyboardTypeNumberPad;
            [makesure release];
			break;}
		case 3:
        {UIButton *btnComit = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            UIButton *btnCancel=[UIButton buttonWithType:UIButtonTypeRoundedRect];
            btnComit.frame=CGRectMake(35, 4, 100, 35);
            btnCancel.frame=CGRectMake(185, 4, 100, 35);
            [btnComit setTitle:@"提交" forState:UIControlStateNormal];
            [btnCancel setTitle:@"取消" forState:UIControlStateNormal];

			[btnComit addTarget:self action:@selector(commitChangePswd) forControlEvents:UIControlEventTouchUpInside];
            [btnCancel addTarget:self action:@selector(cancelChangePswd) forControlEvents:UIControlEventTouchUpInside];

			[cell.contentView addSubview:btnComit];
            [cell.contentView addSubview:btnCancel];

			break;}//这里必须加大括号，再obj－c的case语句中最好加大括号
        default:
			break;
	}
	cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
    
}
-(void)commitChangePswd
{
    NSLog(@"commitChangePswd");
}

-(void)cancelChangePswd
{
    NSLog(@"cancelChangePswd");
}

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [oldpswd release];
    [newpswd release];
    [makesurepswd release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle


- (void)viewDidUnload
{
    self.oldpswd=nil;
    self.newpswd=nil;
    self.makesurepswd=nil;
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}



/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     [detailViewController release];
     */
}

@end
